//
//  XwzxMainViewController.m
//  上海杨浦
//
//  Created by FrankChen on 13-3-26.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "XwzxMainViewController.h"
#import "YpywViewController.h"
#import "JzdtViewController.h"
#import "BmdtViewController.h"
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) 
#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)? (YES):(NO))

@interface XwzxMainViewController ()

@end

@implementation XwzxMainViewController
@synthesize Btn_back;
@synthesize imageView1;
@synthesize EGOview;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (iPhone5) {
        diff=88;
    }
    else{
        diff=0;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
	// Do any additional setup after loading the view.
    [self AddImageView];
    [self AddBtnsToScrollView:[self AddScrollView]];
}

-(void)AddImageView{
    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 420+diff)]autorelease];
    [imageView setImage:[UIImage imageNamed:@"bgImg_xwzx.png"]];
    [self.view addSubview:imageView];
}

-(UIScrollView *)AddScrollView{
    UIScrollView *scrollView=[[[UIScrollView alloc]initWithFrame:CGRectMake(0, 160+diff/1.7, 320, 411)]autorelease];
    [scrollView setContentSize:CGSizeMake(320, 470)];
    [self.view addSubview:scrollView];
    return scrollView;
}


-(void)AddBtnsToScrollView:(UIScrollView *)ScrollView{
    
    CGRect frame1=CGRectMake(25, 0, 270, 83);
    CGRect frame2=CGRectMake(25, 100, 270, 83);
    CGRect frame3=CGRectMake(25, 200, 270, 83);
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"btn_ypyw.png"] forState:UIControlStateNormal];
    btn1.frame = frame1;
    [btn1 addTarget:self action:@selector(Button11Clicked) forControlEvents:UIControlEventTouchDown];
    [btn1 addTarget:self action:@selector(Button1Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"btn_jzdt.png"] forState:UIControlStateNormal];
    btn2.frame = frame2;
    [btn2 addTarget:self action:@selector(Button22Clicked) forControlEvents:UIControlEventTouchDown];
    [btn2 addTarget:self action:@selector(Button2Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn3 setImage:[UIImage imageNamed:@"btn_bmdt.png"] forState:UIControlStateNormal];
    btn3.frame = frame3;
    [btn3 addTarget:self action:@selector(Button33Clicked) forControlEvents:UIControlEventTouchDown];
    [btn3 addTarget:self action:@selector(Button3Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    [ScrollView addSubview:btn1];
    [ScrollView addSubview:btn2];
    [ScrollView addSubview:btn3];
    
}

-(void)Button11Clicked{
    downFlag=1;
}

-(void)Button22Clicked{
    downFlag=2;
}

-(void)Button33Clicked{
    downFlag=3;
}

-(void)Button1Clicked{
    if (downFlag==1) {
        YpywViewController *ypxw=[[YpywViewController alloc]init];
        EGOview=ypxw.view;
        //[views insertObject:ypxw.view atIndex:0];
        [self.view addSubview:ypxw.view];
        [self AddImageView:1];
    }
}

-(void)Button2Clicked{
    if (downFlag==2) {
        JzdtViewController *ypxw=[[JzdtViewController alloc]init];
        EGOview=ypxw.view;
        //[views insertObject:ypxw.view atIndex:0];
        [self.view addSubview:ypxw.view];
        [self AddImageView:2];
    }
}

-(void)Button3Clicked{
    if (downFlag==3) {
        BmdtViewController *ypxw=[[BmdtViewController alloc]init];
        EGOview=ypxw.view;
        //[views insertObject:ypxw.view atIndex:0];
        [self.view addSubview:ypxw.view];
        [self AddImageView:3];
    }
}

-(void) AddImageView:(int)flag{
    imageView1=[[UIImageView alloc] initWithFrame:CGRectMake(0, 87+diff/1.7, 320, 30)];
    [imageView1 setBackgroundColor:[UIColor blueColor]];
    [self.view addSubview:imageView1];
    [self AddLabel:imageView1 :flag];
    [self AddBtn_back];
}

-(void) AddLabel:(UIImageView *)imageView :(int)flag{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(124, 1, 80, 28)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:18.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor blueColor]];
    [label setTextColor:[UIColor whiteColor]];
    switch (flag) {
        case 1:{
            [label setText:@"杨浦要闻"];
            break;}
        case 2:{
            [label setText:@"街镇动态"];
            break;}
        case 3:{
            [label setText:@"部门动态"];
            break;}
    }
    [imageView addSubview:label];
    
}

-(void)AddBtn_back{
    CGRect frame=CGRectMake(21, 87+diff/1.7, 72, 29);
    UIButton *btn_back=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn_back setTag:50];
    [btn_back setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
    btn_back.frame=frame;
    [btn_back addTarget:self action:@selector(Btn_back_Clicked) forControlEvents:UIControlEventTouchUpInside];
    [[self view]addSubview:btn_back];
    Btn_back=btn_back;
}

-(void)Btn_back_Clicked{
    

    [EGOview removeFromSuperview];
    
    [Btn_back removeFromSuperview];
    [imageView1 removeFromSuperview];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
